﻿namespace IntellectShop.Common
{
	using System;
	using System.Text.RegularExpressions;

	public static class ConvertUtils
	{
		public static string RemoveSpecialChars(string text)
		{
			string result = Regex.Replace(String.Format("{0}", text), @"<(.|\n)*?>", string.Empty);
			result = result.Replace("&nbsp;", " ");
			result = result.Replace("&amp;", "'");
			result = result.Replace("\n", " ");
			result = result.Replace("\r", " ");
			result = result.Replace("   ", " ");
			result = result.Replace("  ", " ");
			return result;
		}

		public static DateTime? FromLocalTimeZone(DateTime? date)
		{
			if (!date.HasValue)
			{
				return null;
			}

			TimeZoneInfo customZone = Globals.TimeZone;
			return TimeZoneInfo.ConvertTime(date.Value, TimeZoneInfo.Local, customZone);
		}

		public static DateTime? ToLocalTimeZone(DateTime? date)
		{
			if (!date.HasValue)
			{
				return null;
			}

			TimeZoneInfo customZone = Globals.TimeZone;
			return TimeZoneInfo.ConvertTime(date.Value, customZone, TimeZoneInfo.Local);
		}
	}
}
